<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> {$action} | {:get_opinion('title')}</title>

    <include file="Public:head"/>

</head>
<body class="skin-blue">

{:W('Common/header')}

<div class="wrapper row-offcanvas row-offcanvas-left">
    {:W('Common/sideMenu')}


    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Content Header (Page header) -->


        <section class="content-header">
            <h1>
                {$action}
                <small>{:get_opinion('title')}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{$module_url}"><i class="fa fa-dashboard"></i> {$module}</a></li>
                <li class="active">{$action}</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-12">

                    <!-- /.box-header -->
                    <div class="box-body">


                        <h4>共有{$files}个压缩包文件，共计{$total}&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight:bold;"
                                                                                     id="success"></span></h4>
                        <!-- BEGIN EXAMPLE TABLE PORTLET-->
                        <form method="post">
                            <table
                                    class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th style="width: 8px;">选择</th>
                                    <th>压缩包名称</th>
                                    <th class="hidden-240">打包时间</th>
                                    <th class="hidden-480">文件大小</th>
                                    <th class="">解压</th>
                                </tr>
                                </thead>
                                <tbody id="cache_table">
                                <volist name="list" id="zip">
                                    <tr id="{$zip.file}" align="center">
                                        <td><input type="checkbox" name="zipFiles" value="{$zip.file}"/></td>
                                        <td align="left"><a
                                                href="{:U('Admin/Data/downFile',array('file'=>$zip['file'],'type'=>'zip'))}"
                                                target="_blank">{$zip.file}</a></td>
                                        <td>{$zip.time}</td>
                                        <td>{$zip.size}</td>
                                        <td>
                                            <button class="btn unzip" file="{$zip.file}">解压</button>
                                        </td>
                                    </tr>
                                </volist>
                                </tbody>

                            </table>
                            <div class="form-actions margin ">
                                <div class="row margin">
                                    <button type="button" class="btn btn-success delZipFiles">
                                        <i class="m-icon-swapright m-icon-white"></i>删除所选
                                    </button>

                                    <button type="button" class="btn btn-success unzipSelect">
                                        <i class="m-icon-swapright m-icon-white"></i>解压缩所选
                                    </button>

                                    <button type="button" class="btn btn-primary" id="checkall">全选</button>

                                    <button type="button" class="btn btn-danger" id="check_cancel">取消</button>

                                    <!--<button type="button" class="btn btn-info" id="check_reverse">反选</button>-->
                                </div>
                            </div>

                        </form>


                    </div>
                </div>
            </div>


        </section>
        <!-- /.content -->
    </aside>
    <!-- /.right-side -->
</div>
<!-- ./wrapper -->

<include file="Public:foot"/>
<script>
    jQuery(document).ready(function () {
        $("#cache_table :checkbox").attr("checked", true);
        $("div").addClass("checked");


        $("#checkall").click(function () { //":checked"匹配所有的复选框
            $("#cache_table :checkbox").attr("checked", true); //"#div1 :checked"之间必须有空格checked是设置选中状态。如果为true则是选中fo否则false为不选中
            $("div").addClass("checked");
        });
        $("#check_cancel").click(function () {
            $("#cache_table :checkbox").attr("checked", false);
            $("div").removeClass("checked");
        });
//        //理解用迭代原理each（function(){}）
        $("#check_reverse").click(function () {
            $("#cache_table :checkbox").each(function () {

                $(this).attr("checked", !$(this).attr("checked"));
                $(this).parentsUntil('div').attr("checked", !$(this).attr("checked"));

                //!$(this).attr("checked")判断复选框的状态：如果选中则取反
            });
        });

        //delZipFiles
        $(".delZipFiles").click(function () {
            var obj = document.getElementsByName('zipFiles');
            // var file = [];
            var zipFiles = '';
            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    // file.push({zipFiles:obj[i].value});
                    if (i != obj.length - 1) {
                        zipFiles = zipFiles + (obj[i].value) + ',';
                    }
                    else {
                        zipFiles += obj[i].value;
                    }
                }
            }
            var url = "{:U('Admin/Data/delzipFiles')}";
            $.post(url, {zipFiles: zipFiles}, function (data) {

                //删除成功
                if (data.status == 1) {
                    $("#success").fadeIn().html(data.info);
                    $("#success").fadeOut(3000);

                    setTimeout(function () {
                        top.window.location.reload();
                    }, 1000);
                }
                else {
                    $("#success").fadeIn().html(data.info);
                    $("#success").fadeOut(3000);
                }
            }, "json");

        });

        $(".unzip").click(function () {
            var url_unzip = "{:U('Admin/Data/unzipSqlfile')}";
            $.post(url_unzip, {'zipFiles': $(this).attr("file")}, function (json) {
                var json = eval("(" + json + ")"); //真拙计作者居然注释掉了这个。。。。

                //alert(json.info);

                $(".btn").removeAttr("disabledSubmit");
                if (json.status == 1) {
                    $("#success").fadeIn().html(json.info);
                    $("#success").fadeOut(3000);
                    location.href = json.url;
                }
                else {
                    $("#success").fadeIn().html(json.info);
                    $("#success").fadeOut(3000);
                }
            });
            return false;
        });

        //unzipSelect
        $(".unzipSelect").click(function () {
            if ($("tbody input[type='checkbox']:checked").size() == 0) {
                $("#success").fadeIn().html("请选择你要解压的数据库");
                $("#success").fadeOut(2000);
                return false;
            }

            var obj2 = document.getElementsByName('zipFiles');
            // var file = [];
            var zipFiles2 = '';
            for (var i = 0; i < obj2.length; i++) {
                if (obj2[i].checked) {
                    // file.push({sqlFiles:obj[i].value});
                    if (i != obj2.length - 1) {
                        zipFiles2 = zipFiles2 + (obj2[i].value) + ',';
                    }
                    else {
                        zipFiles2 += obj2[i].value;
                    }
                }
            }
            var url2 = "{:U('Admin/Data/unzipSqlfile')}";
            $.post(url2, {zipFiles: zipFiles2}, function (data) {

                //解压成功
                if (data.status == 1) {
                    $("#success").fadeIn().html(data.info);
                    $("#success").fadeOut(3000);
                    location.href = data.url;
                }
                else {
                    $("#success").fadeIn().html(data.info);
                    $("#success").fadeOut(3000);
                }
            }, "json");
        });
    });
</script>
</body>
</html>